package com.itheima.guava.samples.demo.baseDemo;

import com.google.common.base.Charsets;

import java.io.UnsupportedEncodingException;

/**
 * Charsets：字符集常量
 */
public class CharsetsDemo {

    private static final String string = "test";//测试用字符串

    public static void main(String[] args) {
        testCharsets();
        original();
        testCharsets2();
    }

    public static void testCharsets() {
        System.out.println(Charsets.UTF_8);
        System.out.println(Charsets.ISO_8859_1);
        System.out.println(Charsets.US_ASCII);
        System.out.println(Charsets.UTF_16);
        System.out.println(Charsets.UTF_16BE);
        System.out.println(Charsets.UTF_16LE);
        System.out.println(Charsets.UTF_8);
    }

    public static void original() {
        byte[] bytes;
        //原始做法
        try {
            bytes = string.getBytes("UTF-8");
            System.out.println(bytes);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static void testCharsets2() {
        byte[] bytes = string.getBytes(Charsets.UTF_8);
        System.out.println(bytes);
    }
}
